//
//  ProgressVC.swift
//  FromWatchToCircle
//
//  Created by 张海峰 on 2018/6/1.
//  Copyright © 2018年 张海峰. All rights reserved.
//
/*写该demo的目的：主要是想从时钟开始，一步步窥见项目中和圆有关的东西，从而学习巩固，加深理解。
 项目不定时更新。感觉我这个demo对你有启发或者帮助，欢迎fork 感谢star
 https://github.com/FighterLightning/FromWatchToCircle.git
 */
import UIKit

class ProgressVC: UIViewController {
    var timer:Timer!
    let ballProgressView: BallProgressView = BallProgressView()
    let loopProgressView: LoopProgressView = LoopProgressView()
    let pieLoopProgressView: PieLoopProgressView = PieLoopProgressView()
    let pieProgressView: PieProgressView = PieProgressView()
    let rotationLoopProgressView: RotationLoopProgressView = RotationLoopProgressView()
    let transparentPieProgressView: TransparentPieProgressView = TransparentPieProgressView()
     let someSectorView: SomeSectorView = SomeSectorView()
    override func viewDidLoad() {
        super.viewDidLoad()
        self.view.backgroundColor = UIColor.white
        self.title = "画圆进度条"
        let addBtn: UIButton = UIButton.init(type: UIButtonType.custom)
        addBtn.frame = CGRect.init(x: 0, y: ScreenHeight - 30, width: ScreenWidth/3, height: 30)
        addBtn.backgroundColor = ZHFColor.red
        addBtn.setTitle("添加进度条", for: UIControlState.normal)
        addBtn.setTitleColor(UIColor.white, for: UIControlState.normal)
        addBtn.addTarget(self, action: #selector(addBtnClick), for: UIControlEvents.touchUpInside);
        self.view.addSubview(addBtn)
        let startBtn: UIButton = UIButton.init(type: UIButtonType.custom)
        startBtn.frame = CGRect.init(x: ScreenWidth/3, y: ScreenHeight - 30, width: ScreenWidth/3, height: 30)
        startBtn.backgroundColor = ZHFColor.zhf_selectColor
        startBtn.setTitle("动起来", for: UIControlState.normal)
        startBtn.setTitleColor(UIColor.white, for: UIControlState.normal)
        startBtn.addTarget(self, action: #selector(startBtnClick), for: UIControlEvents.touchUpInside);
        self.view.addSubview(startBtn)
        let stopBtn: UIButton = UIButton.init(type: UIButtonType.custom)
        stopBtn.frame = CGRect.init(x:ScreenWidth*2/3, y: ScreenHeight - 30, width: ScreenWidth/3, height: 30)
        stopBtn.backgroundColor = UIColor.blue
        stopBtn.setTitle("停止", for: UIControlState.normal)
        stopBtn.setTitleColor(UIColor.white, for: UIControlState.normal)
        stopBtn.addTarget(self, action: #selector(stopBtnClick), for: UIControlEvents.touchUpInside);
        self.view.addSubview(stopBtn)
    }
    @objc func addBtnClick(){
        let W: CGFloat = 100
        let H: CGFloat = 100
        
        ballProgressView.progress = 0.1
        ballProgressView.defaultTextFont = 14
        self.view.addSubview(ballProgressView.initBaseProgressView(frame: CGRect.init(x: (ScreenWidth/2 - W)/2, y: 65, width: W, height: H)))
        
        loopProgressView.progress = 0.05
        loopProgressView.defaultTextFont = 13
        self.view.addSubview(loopProgressView.initBaseProgressView(frame: CGRect.init(x: ScreenWidth/2 + (ScreenWidth/2 - W)/2, y: 65, width: W, height: H)))
        
        pieLoopProgressView.progress = 0.1
        pieLoopProgressView.defaultTextFont = 14
        self.view.addSubview(pieLoopProgressView.initBaseProgressView(frame: CGRect.init(x: (ScreenWidth/2 - W)/2, y: 200, width: W, height: H)))
        
        pieProgressView.progress = 0.05
        pieProgressView.defaultTextFont = 13
        self.view.addSubview(pieProgressView.initBaseProgressView(frame: CGRect.init(x: ScreenWidth/2 + (ScreenWidth/2 - W)/2, y:200, width: W, height: H)))
        
        rotationLoopProgressView.progress = 0.1
        rotationLoopProgressView.defaultTextFont = 10
        self.view.addSubview(rotationLoopProgressView.initBaseProgressView(frame: CGRect.init(x: (ScreenWidth/2 - W)/2, y: 350, width: W, height: H)))
        rotationLoopProgressView.Start()
        
        transparentPieProgressView.progress = 0.05
        transparentPieProgressView.defaultTextFont = 13
self.view.addSubview(transparentPieProgressView.initBaseProgressView(frame: CGRect.init(x: ScreenWidth/2 + (ScreenWidth/2 - W)/2, y:350, width: W, height: H)))
        //画饼状图
        self.view.addSubview(someSectorView.initSomeSectorView(frame: CGRect.init(x: (ScreenWidth/2 - W)/2, y: 500, width: W, height: H)))
        someSectorView.sectors = [0.15,0.25,0.1,0.2,0.2,0.05]//其和不能大于1
        
    }
    @objc func startBtnClick() {
       timer = Timer.scheduledTimer(timeInterval: 1, target: self, selector: #selector(progressStart), userInfo: nil, repeats: true)
    }
    @objc func stopBtnClick() {
        timer.invalidate()
    }
    @objc func progressStart() {
        ballProgressView.progress += 0.05
        loopProgressView.progress += 0.05
        pieLoopProgressView.progress += 0.05
        pieProgressView.progress += 0.05
        rotationLoopProgressView.progress += 0.05
        transparentPieProgressView.progress += 0.05
    }

}
